home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / filutil / direxe.zip / RUNEXE.C < prev    next >
C/C++ Source or Header  |  1994-01-12  |  5KB  |  131 lines

  1. #include <dirent.h> /* pour les fonctions opendir,readdir ... */
  2. #include <string.h> /* pour la fonction strstr */
  3. #include <stdio.h> /* pour printf */
  4. #include <stdlib.h> /* pour exit */
  5. #include <conio.h> /* pour wherex,wherey,getch */
  6. #include <process.h> /* pour spawnl */
  7.  
  8. #define EXE 0
  9. #define COM 1
  10. #define BAT 2
  11. #define MAXEXE 100 /* nbr max d'entree dans la table des pointeurs */
  12. #define MAXLIN 25 /* nbr de ligne ecran geree par mon prog */
  13. #define MAXCOL 5 /* 5 fichier par ligne (5*16=80) */
  14.  
  15. void main () {
  16.  
  17.     DIR *dirdes ;
  18.     struct dirent *filedes ;
  19.     const char *line = "────────────────────────────────────────────────────────────────────────────────" ;
  20.     int i , j , nbr [3] = {0,0,0} ;
  21.     char *p [3][MAXEXE] ; /* tableau a 2 dim de pointeur vers des string */
  22.     char *q [MAXLIN][MAXCOL] ; /* idem */
  23.     int actline , actcol , touche , badnumber , badline [4] = {0,0,0,0} ;
  24.  
  25. /* ouvre le flux du dir courant */
  26.  
  27.     if ((dirdes = opendir (".")) == NULL) {
  28.         printf ("Warning, can't open the directory !!!") ;
  29.     exit (1) ;
  30.     }
  31.  
  32. /* ATTENTION, DOS RENVOIE LES NOMS DE DIR. EN MAJUSCULES */
  33.  
  34.     while ((filedes = readdir (dirdes)) != NULL ) {
  35.         if (strstr (filedes->d_name,".EXE") != NULL) {
  36.             p [EXE][nbr [EXE]] = (char *) malloc (sizeof (char)*13) ;
  37.             strcpy (p [EXE][nbr [EXE]],filedes->d_name) ;
  38.             nbr [EXE]++ ;
  39.         } else if (strstr (filedes->d_name,".COM") != NULL) {
  40.             p [COM][nbr [COM]] = (char *) malloc (sizeof (char)*13) ;
  41.             strcpy (p [COM][nbr [COM]],filedes->d_name) ;
  42.             nbr [COM]++ ;
  43.         } else if (strstr (filedes->d_name,".BAT") != NULL) {
  44.             p [BAT][nbr [BAT]] = (char *) malloc (sizeof (char)*13) ;
  45.             strcpy (p [BAT][nbr [BAT]],filedes->d_name) ;
  46.             nbr [BAT]++ ;
  47.         }
  48.     }
  49.     closedir (dirdes) ;
  50.  
  51. /* initialise le tableau q */
  52.  
  53.     for (i=0 ; i<MAXLIN ; i++)
  54.         for (j=0 ; j<MAXCOL ; j++)
  55.             q [i][j] = NULL ; /* securite et test apres*/
  56.  
  57. /* affiche le resultat */
  58.  
  59.     clrscr () ; /* permet de ne pas faire scroller l'ecran; curpos = (1,1) */
  60.     printf ("Runexe Coded By Sam In 1994 - The Flamoots Production\n\n") ;
  61.     badnumber = -1 ;
  62.     badline [++badnumber] = wherey ()-1 ;
  63.     printf ("%s",line) ;
  64.     if (nbr[EXE] + nbr[COM] + nbr[BAT]) {
  65.         for (i=0 ; i <= 2 ; i++)
  66.             if (nbr [i]) {
  67.                 for (j=0 ; j < nbr [i] ; j++) {
  68.                     q [wherey()-1][(wherex()-1)>>4] = p [i][j] ;
  69.                     printf ("%16s",p [i][j]) ;
  70.                 }
  71.                 if (nbr [i] % 5) printf ("\n") ; /* 5 exec par ligne */
  72.                 badline [++badnumber] = wherey ()-1 ;
  73.                 printf ("%s",line) ;
  74.             }
  75.         printf ("\nTotal executable(s) file(s) founded : %d\n",nbr[EXE]+nbr[COM]+nbr[BAT]) ;
  76.     } else {
  77.         printf ("\nNo executables files where found !!!\n") ;
  78.         exit (0) ;
  79.     }
  80.  
  81.     actcol = 0 ; /* actcol = colonne de 16 caracteres */
  82.     actline = badline [0]+1 ;
  83.  
  84.     do {
  85.         gotoxy ((actcol<<4)+1,actline+1) ; /* (col,lig) */
  86.         if (q [actline][actcol] != NULL) printf ("-->") ;
  87.         gotoxy ((actcol<<4)+1,actline+1) ; /* prepare l'effacement */
  88.         touche = getch () ;
  89.         if (!touche) touche = getch () ;
  90.         switch (touche) {
  91.             case 27 : {
  92.                 gotoxy (1,badline [badnumber]+4) ;
  93.                 exit (0) ; /* Back To Dos (a la ligne) */
  94.             }
  95.             case 77 : { /* fleche droite */
  96.                 if (actcol<4) {
  97.                     printf ("   ") ; /* efface la fleche */
  98.                     actcol++ ;
  99.                 }
  100.                 break ;
  101.             }
  102.             case 75 : { /* fleche gauche */
  103.                 if (actcol>0) {
  104.                     printf ("   ") ;
  105.                     actcol-- ;
  106.                 }
  107.                 break ;
  108.             }
  109.             case 80 : { /* fleche bas */
  110.                 if (actline<badline[badnumber]-1) {
  111.                     printf ("   ") ;
  112.                     actline++ ;
  113.                     if ((actline == badline [1]) || (actline == badline [badnumber-1])) actline++ ;
  114.                 }
  115.                 break ;
  116.             }
  117.             case 72 : { /* fleche haut */
  118.                 if (actline>badline[0]+1) {
  119.                     printf ("   ") ;
  120.                     actline-- ;
  121.                     if ((actline == badline [1]) || (actline == badline [badnumber-1])) actline-- ;
  122.                 }
  123.                 break ;
  124.             }
  125.         }
  126.         if (q [actline][actcol] == NULL) touche = 0 ; /* annule ENTER */
  127.     } while (touche != 13) ;
  128.     gotoxy (1,badline [badnumber]+5) ;
  129.     i = spawnl (P_WAIT,q [actline][actcol],NULL) ;
  130.     exit (i) ;
  131. }